from django.db import models

# Create your models here.


class MeetingInfo(models.Model):
    meetingRoom = models.CharField(max_length=50)
    title = models.CharField(max_length=100)
    content = models.TextField()
    attendant = models.TextField()
    inform_time = models.CharField(max_length=50)
    username = models.CharField(max_length=50)
    sendTime = models.CharField(max_length=100)
    status = models.CharField(max_length=10)

    class Meta:
        db_table = 'tb_meeting_info'


class ExceptionInfo(models.Model):
    product = models.CharField(max_length=50)
    line = models.CharField(max_length=50)
    station = models.CharField(max_length=50)
    description = models.TextField()
    attendant = models.TextField()
    exception_time = models.CharField(max_length=50)
    username = models.CharField(max_length=50)
    sendTime = models.CharField(max_length=100)
    img = models.CharField(max_length=100)
    status = models.CharField(max_length=10)

    class Meta:
        db_table = 'tb_exception_info'


class GroupInfo(models.Model):
    group_name = models.CharField(max_length=100)
    member = models.TextField()
    employee_name = models.CharField(max_length=50)
    class Meta:
        db_table = 'tb_group_info'


class SubscriptionInfo(models.Model):
    product = models.CharField(max_length=50)
    line = models.CharField(max_length=50)
    station = models.CharField(max_length=50)
    username = models.CharField(max_length=50)

    class Meta:
        db_table = 'tb_subscription_info'


class TbOrgLevel(models.Model):
    """
    组织架构等级表，记录每个组织单元属于哪一个级别
    """
    level = models.IntegerField(unique=True, primary_key=True)
    level_name = models.CharField(max_length=100)
    level_code = models.CharField(max_length=50)
    id = models.IntegerField(unique=True)
    # duty = models.ForeignKey(Duty)

    class Meta:
        db_table = "tb_org_level"

    def __str__(self):
        return self.level_name

    # def get_new_level(self):
    #     obj = OrgLevel.objects.all().order_by("-level")
    #     if obj:
    #         return self.get_level(front=obj[0].level)
    #     else:
    #         return 10


class TbOrg(models.Model):
    org_name = models.CharField(max_length=100)
    parent_id = models.IntegerField(blank=True, null=True)
    create_date = models.DateTimeField()
    org_code = models.CharField(max_length=50)
    cost_code = models.CharField(max_length=50, blank=True, null=True)
    org_desc = models.CharField(max_length=500, blank=True, null=True)
    org_desc2 = models.CharField(max_length=500, blank=True, null=True)
    org_level = models.ForeignKey(TbOrgLevel)
    is_active = models.IntegerField()
    org_people = models.IntegerField()
    org_people_all = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'tb_org'


class TbOrgRole(models.Model):
    name = models.CharField(max_length=100)
    code = models.CharField(max_length=50, blank=True, null=True)
    desc = models.CharField(max_length=500, blank=True, null=True)
    level = models.IntegerField(unique=True)
    create_date = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'tb_org_role'


class TbUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=30)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()
    nfc_id = models.CharField(db_column='NFC_id', max_length=100, blank=True, null=True)  # Field name made lowercase.
    ext = models.CharField(max_length=50, blank=True, null=True)
    short_number = models.CharField(max_length=50, blank=True, null=True)
    mobile_phone = models.CharField(max_length=50, blank=True, null=True)
    head = models.CharField(max_length=100, blank=True, null=True)
    sign = models.CharField(max_length=100, blank=True, null=True)
    entry_date = models.DateField()
    sex = models.CharField(max_length=10)

    class Meta:
        db_table = 'tb_user'

    # def __str__(self):
    #     return self.username


class TbUserOrg(models.Model):
    create_date = models.DateTimeField()
    org = models.ForeignKey(TbOrg)
    org_role = models.ForeignKey(TbOrgRole)
    user = models.ForeignKey(TbUser)

    class Meta:
        managed = False
        db_table = 'tb_user_org'


class UserList(models.Model):
    user = models.ForeignKey(TbUser, blank=True, null=True)
    user_list = models.TextField(blank=True, null=True)
    timeout = models.IntegerField(blank=True, null=True)
    desc2 = models.CharField(max_length=255, blank=True, null=True)
    desc3 = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        db_table = 'tb_user_list'